﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional

namespace Demo.Net.EFCoreEnv.Migrations
{
    /// <inheritdoc />
    public partial class data : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Owners",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Sex = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    IdNumber = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    Phone = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Home = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    License = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Room = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Owners", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "ParkingSpaces",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Code = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    Photo = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Type = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Status = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    RentStartTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    RentEndTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ParkingSpaces", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Feedbacks",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    OwnerId = table.Column<int>(type: "int", nullable: false),
                    Title = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Photo = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Feedbacks", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Feedbacks_Owners_OwnerId",
                        column: x => x.OwnerId,
                        principalTable: "Owners",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "RentRecords",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    OwnerId = table.Column<int>(type: "int", nullable: false),
                    ParkingSpaceId = table.Column<int>(type: "int", nullable: false),
                    RentStartTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    RentEndTime = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_RentRecords", x => x.Id);
                    table.ForeignKey(
                        name: "FK_RentRecords_Owners_OwnerId",
                        column: x => x.OwnerId,
                        principalTable: "Owners",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_RentRecords_ParkingSpaces_ParkingSpaceId",
                        column: x => x.ParkingSpaceId,
                        principalTable: "ParkingSpaces",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.InsertData(
                table: "Owners",
                columns: new[] { "Id", "Home", "IdNumber", "License", "Name", "Password", "Phone", "Room", "Sex" },
                values: new object[,]
                {
                    { 1, "福建省闽西职业技术学院", "123432345678976543", "闽A186", "admin", "aaa123456", "13500350606", 220, "男" },
                    { 2, "福建省闽西职业技术学院", "123432345678976567", "闽A186", "小李", "123", "11111111111", 110, "女" },
                    { 3, "福建省闽西职业技术学院", "450881200205302035", "闽A8888", "李涛", "abc123456", "15977585758", 110, "女" }
                });

            migrationBuilder.InsertData(
                table: "ParkingSpaces",
                columns: new[] { "Id", "Code", "Photo", "RentEndTime", "RentStartTime", "Status", "Type" },
                values: new object[,]
                {
                    { 1, "F888", "123.jpg", new DateTime(2023, 7, 1, 16, 3, 5, 477, DateTimeKind.Local).AddTicks(6832), new DateTime(2023, 7, 1, 16, 3, 5, 477, DateTimeKind.Local).AddTicks(6814), "已出租", "室内" },
                    { 2, "A666", "222.jpg", new DateTime(2023, 7, 1, 16, 3, 5, 477, DateTimeKind.Local).AddTicks(6834), new DateTime(2023, 7, 1, 16, 3, 5, 477, DateTimeKind.Local).AddTicks(6833), "未出租", "室内" },
                    { 3, "D999", "333.jpg", new DateTime(2023, 7, 1, 16, 3, 5, 477, DateTimeKind.Local).AddTicks(6836), new DateTime(2023, 7, 1, 16, 3, 5, 477, DateTimeKind.Local).AddTicks(6835), "已损坏", "室外" }
                });

            migrationBuilder.InsertData(
                table: "Feedbacks",
                columns: new[] { "Id", "Description", "OwnerId", "Photo", "Title" },
                values: new object[,]
                {
                    { 1, "车位空间太小，无法容纳我的大型 SUV。", 1, "img1.jpg", "车位空间太小" },
                    { 2, "车位周边卫生需要加强清理。", 2, "img2.jpg", "车位卫生有待改进" }
                });

            migrationBuilder.InsertData(
                table: "RentRecords",
                columns: new[] { "Id", "OwnerId", "ParkingSpaceId", "RentEndTime", "RentStartTime" },
                values: new object[,]
                {
                    { 1, 2, 1, new DateTime(2023, 7, 1, 16, 3, 5, 477, DateTimeKind.Local).AddTicks(6885), new DateTime(2023, 7, 1, 16, 3, 5, 477, DateTimeKind.Local).AddTicks(6884) },
                    { 2, 1, 2, new DateTime(2023, 7, 1, 16, 3, 5, 477, DateTimeKind.Local).AddTicks(6887), new DateTime(2023, 7, 1, 16, 3, 5, 477, DateTimeKind.Local).AddTicks(6886) }
                });

            migrationBuilder.CreateIndex(
                name: "IX_Feedbacks_OwnerId",
                table: "Feedbacks",
                column: "OwnerId");

            migrationBuilder.CreateIndex(
                name: "IX_Owners_IdNumber",
                table: "Owners",
                column: "IdNumber",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_Owners_Phone",
                table: "Owners",
                column: "Phone",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_ParkingSpaces_Code",
                table: "ParkingSpaces",
                column: "Code",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_RentRecords_OwnerId",
                table: "RentRecords",
                column: "OwnerId");

            migrationBuilder.CreateIndex(
                name: "IX_RentRecords_ParkingSpaceId",
                table: "RentRecords",
                column: "ParkingSpaceId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Feedbacks");

            migrationBuilder.DropTable(
                name: "RentRecords");

            migrationBuilder.DropTable(
                name: "Owners");

            migrationBuilder.DropTable(
                name: "ParkingSpaces");
        }
    }
}
